#include <ie.au3>
#include <file.au3>
#include <biosinfo.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <testWirelessInfo.au3>
#include <GUIEdit.au3>

Global $pathLog, $frmMain, $editStatus
$pathLog = @WorkingDir & "\Healthcheck logs\" & @ComputerName & "-" & @YEAR & @MON & @MDAY & ".log"
TraySetToolTip( "Healthcheck script" & @CRLF & "version 0.2b" & @CRLF & @LogonDomain & "\" & @UserName & @CRLF & @ComputerName )

#Region GUI setup >>

$frmMain = GUICreate( " Healthcheck v0.2b", 500, 230, @DesktopWidth-510, @DesktopHeight-300 )
GUISetBkColor( 0xDDDDDD )
$editStatus = GUICtrlCreateEdit( "", 2, 2, 496, 226, BitOR($ES_MULTILINE,$ES_READONLY,$WS_VSCROLL) )
GUICtrlSetBkColor( $editStatus, 0x000000 )
GUICtrlSetFont( $editStatus, 8, 400, 0, "Lucida Console" )
GUICtrlSetColor( $editStatus, 0xEEEEFF )
GUISetState(@SW_SHOW)

#EndRegion GUI setup <<

_Main()

Func _Main()
	Local $ou, $MA, $nicSet, $ieSDP, $txtLog, $memTotal, $regID, $qID, $genID
	Local $aaState, $ldState, $synState, $ssoState, $invState, $pnState, $maState
	Local $timer = TimerInit()
	Local $postInstallBat, $postInstallExe, $tempBat
	Local $biosInfo = _biosInfo()
	Local $ieVersion = FileGetVersion( @ProgramFilesDir & "\Internet Explorer\iexplore.exe" )
	Local $DN = _getDN(@ComputerName)
	Local $tmrPNAgent, $tmrAL

	DirCreate( @WorkingDir & "\Healthcheck logs" )

	$memTotal = MemGetStats()
	$regID = RegRead( "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName" )

	upStatus( "|==> Healthcheck started ==>" )
	upStatus( "Computer name:	" & @ComputerName )
	if NOT StringIsAlNum( @ComputerName ) Then
		upStatus( "Computer name contains non-alphanumeric characters!" )
	EndIf
	upStatus( "DN:		" & $DN )
	upStatus( "Model:	" & $biosInfo[0] )
	upStatus( "Serial:	" & $biosInfo[1] )
	upStatus( "BIOS:		" & $biosInfo[2] )
	upStatus( "Memory:	" & Round($memTotal[1]/1024, -1) & "MB" )
	upStatus( "Display res:	" & @DesktopWidth & "x" & @DesktopHeight )
	upStatus( "IE version:	" & $ieVersion )

	; QPM / Static IP check
	if FileExists( @DesktopCommonDir & "\QPM.lnk" ) Then
		if @IPAddress2 == "0.0.0.0" Then
			dim $QS = 1
			upStatus( "QS Static IP:	" & @IPAddress1 )
		Else
			dim $QS = 1
			upStatus( "QS Static IP:	" & @IPAddress2 )
		EndIf
	EndIf

	#Region autologon

	upStatus( "Check and correct OU now", 0 )
	ShellExecuteWait( "" ) ; path removed for security

	; regID is what is found in HKLM/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/DefaultUserName
	; genID is the first local profile matching the hospital code search string
	; if regID doesn't contain the hospital code, then regID is set to the results of this search
	if NOT StringInStr( $regID, "" ) Then
		$genID = FileFindFirstFile( "c:\documents and settings\*" )
		$regID = FileFindNextFile( $genID )
	EndIf

	upStatus( "DefaultUserName:	" & $regID )

	$qID = MsgBox( 3, "Clinical ID", "Clinical ID found: " & $regID & "." & @CRLF & @CRLF & "Is this correct?" )

	; Yes
	if $qID = 6 Then
		upStatus( "Clinical ID script ran w/ " & $regID )
		$tmrAL = TimerInit()
		setAL($regID)
		$postInstallBat = FileInstall( "postinstall.bat", "c:\documents and settings\" & $regID & "\Start Menu\Programs\Startup\", 1 )
		$postInstallExe = FileInstall( "postinstall.exe", "c:\documents and settings\" & $regID & "\Desktop\", 1 )
	; No
	ElseIf $qID = 7 Then
		$genID = InputBox( "Clinical ID", "Enter new clinical ID", $regID )
		upStatus( "Clinical ID script ran w/ " & $genID )
		$tmrAL = TimerInit()
		setAL($genID)
		$postInstallBat = FileInstall( "postinstall.bat", "c:\documents and settings\" & $genID & "\Start Menu\Programs\Startup\", 1 )
		$postInstallExe = FileInstall( "postinstall.exe", "c:\documents and settings\" & $genID & "\Desktop\", 1 )
	EndIf

	if $tmrAL Then upStatus( "Autologon time:	" & timeFormat(TimerDiff($tmrAL)) )

	#EndRegion autologon

	; create clinical ID startup folder if it doesn't exist
	; unfortunately this method will not work due to windows making a username.DOMAIN folder when the directory already exists.
	if $qID = 6 Then
		if NOT FileExists( "c:\documents and settings\" & $regID & "\Start Menu\Programs\Startup" ) Then DirCreate( "c:\documents and settings\" & $regID & "\Start Menu\Programs\Startup" )
	ElseIf $qID = 7 Then
		if NOT FileExists( "c:\documents and settings\" & $genID & "\Start Menu\Programs\Startup" ) Then DirCreate( "c:\documents and settings\" & $genID & "\Start Menu\Programs\Startup" )
	EndIf

	; install postinstall.exe and .bat if possible

	if $postInstallBat AND $postInstallExe Then
		upStatus( "Postinstall files copied." )
	ElseIf $postInstallBat AND NOT $postInstallExe Then
		upStatus( "Could not copy postinstall.exe" )
	ElseIf NOT $postInstallBat AND $postInstallExe Then
		upStatus( "Could not copy postinstall.bat" )
	Else
		upStatus( "Could not copy postinstall files or no ID set." )
	EndIf


	; if wireless utility processes exist, try to grab the stats from them
	Select
	Case ProcessExists("iFrmewrk.exe")
		getWireless(1)
	Case ProcessExists("orinoco.exe")
		getWireless(2)
	Case FileExists(@SystemDir & "\BCMWLCPL.CPL" )
		getWireless(3)
	Case StringInStr( $biosInfo[0], "LifeBook" )
		getWireless(4)
	EndSelect

	; App checks/installs

	Dim $instQ

	$ldState = instLD()
	$aaState = instAA()
	$invState = instInv()

	; if clinical ID launched, install SSO and Synapse
	if $qID = 6 or $qID = 7 Then
		$ssoState = instSSO()
		$synState = instSynapse()
	EndIf

	$tmrPNAgent = TimerInit()

	$pnState = instPNAgent()

	upStatus( "PNAgent install time:	" & timeFormat(TimerDiff($tmrPNAgent)) )

	$maState = instMA()

	setNIC()

	if $ldState then upStatus( "LANDesk return code:		" & $ldState )
	if $aaState then upStatus( "AccessAnyware return code:	" & $aaState )
	if $invState then upStatus( "Invision return code:		" & $invState )
	if $ssoState then upStatus( "SSO return code:			" & $ssoState )
	if $synState then upStatus( "Synapse return code:		" & $synState )
	if $pnState then upStatus( "PNAgent return code:		" & $pnState )
	if $maState then upStatus( "McAfee return code:		" & $maState )

	upStatus( "Deleting temporary files" )
	$tempBat = FileInstall( "stc.bat", "c:\temp\stc.bat" )
	sleep(2000)
	if $tempBat Then
		ShellExecuteWait( "c:\temp\stc.bat", "", "", "", @SW_HIDE )
		FileDelete( "c:\temp\stc.bat" )
		upStatus( "Temp files deleted" )
	Else
		upStatus( "Problem deleting temp files" )
	EndIf

	upStatus( "Healthcheck completed after " & timeFormat(TimerDiff($timer)) )

	MsgBox(64, "Healthcheck complete", "Don't forget to:" & @CRLF & @CRLF & _
		"- update Quickbase" & @CRLF & _
		"- restart w/ clinical ID" & @CRLF & _
		"- set default printer(s)" & @CRLF & _
		"- verify that all apps run under clinical ID" & @CRLF & @CRLF & _
		"	Ready to check BIOS... " )

	ShellExecute( @StartMenuCommonDir & "\Programs\LANDesk Management\Inventory Scan.lnk" )

	if NOT FileExists( @desktopcommondir & "\QPM.lnk" ) then
		; pass the computer model and current BIOS level
		checkBios($biosInfo[0], $biosInfo[2])
	Else
		upStatus( "QS Detected, skipping BIOS" )
	EndIf

	upStatus( "Window may be closed now.", 0 )
	dim $guiMsg
	do
		$guiMsg = GUIGetMsg()
		Sleep(10)
	Until GUIGetMsg() = $GUI_EVENT_CLOSE
	Exit
EndFunc

#Region App installs >>

func instLD()	; GOOD
	Dim $ldState

	if NOT FileExists( @programfilesdir & "\LANDesk\LDClient" ) Then
		upStatus( "Installing:	LANDesk" )
		$ldState = ShellExecuteWait( "" ) ; path removed for security
	Else
		$ieSDP = _IECreate( "http://127.0.0.1:9595/policy.cgi.exe", 0, 0 )

		if StringInStr( _IEBodyReadText( $ieSDP ), "The webpage cannot be found" ) Then
			upStatus( "LANDesk SDP not working" )
			upStatus( "Installing:	LANDesk" )
			$ldState = ShellExecuteWait( "" ) ; path removed for security
		EndIf

		upStatus( "Found:	LANDesk" )

		_IEQuit( $ieSDP )
	EndIf

	Return $ldState

EndFunc

func instMA()	; GOOD
	Local $instState, $maVersion, $inst = 0
	$maVersion = FileGetVersion( @ProgramFilesDir & "\McAfee\Common Framework\UdaterUI.exe" )

	if FileExists( @ProgramFilesDir & "\McAfee\Common Framework\" ) Then
		upStatus( "Found:	McAfee" )
		upStatus( "Version:	" & $maVersion )

		if StringLeft( $maVersion, 1 ) < 4 Then
			$inst = 1
		EndIf
	Else
		$inst = 1
	EndIf

	if $inst = 1 Then
		upStatus( "Installing:	McAfee" )

		$instState = ShellExecute( "" ) ; path removed for security
		WinWait( "McAfee Agent", "completed successfully." )

		WinActivate( "McAfee Agent", "completed successfully." )
		ControlClick( "McAfee Agent", "completed successfully.", 3001 )

		Return $instState
	EndIf

EndFunc ; <== instMA

func instAA()	; ALMOST GOOD
	Local $instState

	if FileExists( @DesktopCommonDir & "\ accessANYware.lnk" ) Then
		upStatus( "Found:	AccessAnyware" )
		Return 1
	Else
		upStatus( "Installing:	 AccessAnyware" )

		ShellExecute( "" ) ; path removed for security

		WinWaitActive( "AccessAnyware " )
		while WinExists( "AccessAnyware " )
			if WinExists( "Java 2 Runtime Environment, SE", "You must restart" ) Then
				WinActivate( "Java 2 Runtime Environment, SE", "You must restart" )
				ControlClick( "Java 2 Runtime Environment, SE", "You must restart", 3002 )
			EndIf
			sleep(500)
		WEnd
	EndIf

	; launch and config
	upStatus( "Launching:	AccessAnyware" )

	; check for AA shortcut and make one if it AIN'T THUR
	if NOT FileExists(@DesktopCommonDir & "\accessANYware.lnk") Then
		FileInstall( "accessANYware.lnk", @DesktopCommonDir & "\accessANYware.lnk" )
	EndIf

	ShellExecuteWait( @DesktopCommonDir & "\ accessANYware.lnk" )

	#cs WAIT ON THIS UNTIL TESTING POSSIBLE
	WinWaitActive( "Create Shortcut...", "", 15 )
	if WinExists( "Create Shortcut..." ) Then
		sleep(5000)
		send( "!n" )
		WinWaitActive( "Register Workstation", "", 30 )
		send( "{TAB 2} h" )
		sleep(100)
		send("{TAB 3} {ENTER}" )
		WinWaitActive( "Please log in", "", 30 )
		sleep(100)
		send("{TAB 4} {ENTER}" )
	EndIf
	#ce


	Return $instState
EndFunc	; <== instAA

func instInv()	; GOOD
	Local $instState

	if FileExists( @DesktopCommonDir & "\INVISION.lnk" ) Then
		upStatus( "Found:	Invision" )
		return
	Else
		upStatus( "Installing:	Invision" )
		$instState = ShellExecuteWait( "" ) ; path removed for security

		#cs
		WinWait( "Invision", "", 30)


		While WinExists( "Invision" )
			winwait( "Nebo Eligibility Interface", "Welcome to the", 15 )
		WEnd

		if WinExists( "Invision" ) Then
			WinActivate( "Nebo Eligibility Interface", "Welcome to the" )
			ControlClick( "Nebo Eligibility Interface", "Welcome to the", 2293 )

			winwaitactive( "Nebo Eligibility Interface", "successfully installed", 60 )
			ControlClick( "Nebo Eligibility Interface", "successfully installed", 2304 )

		EndIf
		#ce
	EndIf
	#cs NO WORKY LOL
	dim $objInv = _IECreate( "http://oasg/thr_prod/clientY0ADA2K1.html", 0, 0 )

	if StringInStr( _IEBodyReadHTML( $objInv ), "startApplet()" ) Then
		upStatus( "Invision launched and working" )
	Else
		upStatus( "Invision shortcut not working, try re-installing java" )
	EndIf

	_IEQuit( $objInv )
	#ce

	Return $instState

EndFunc ; <== instINV

func instSynapse()	; GOOD, PUT CLINICAL SETTINGS IN POSTINSTALL
	Local $instState

	if FileExists( @ProgramFilesDir & "\Fuji Medical System\Synapse" ) Then
		upStatus( "Found:	Synapse" )
		Return
	Else
		upStatus( "Installing:	Synapse" )

		$instState = ShellExecuteWait( "" )  ; path removed for security
		;ShellExecuteWait( "" )  ; path removed for security
	EndIf

	Return $instState
EndFunc ; <== instSynapse

func instPNAgent()	; GOOD, WATCH FOR XENAPP/METAFRAME ISSUES
	Local $instState

	if FileExists( @ProgramFilesDir & "\Citrix\ICA Client\pnagent.exe" ) Then
		upStatus( "Found:	PNAgent" )
		Return
	Else
		upStatus( "Installing:	PNAgent" )
		Sleep(2000)
		$instState = ShellExecuteWait( "" )  ; path removed for security
	EndIf

	Return $instState
EndFunc ; <== instPNAgent

func instSSO()	; GOOD
	Local $instState

	if FileExists( @ProgramFilesDir & "\CA\eTrust SSO\Client\SsoAgent.exe" ) Then
		upStatus( "Found:	SSO" )
		Return
	Else
		upStatus( "Installing:	SSO" )
		$instState = ShellExecute( "" )  ; path removed for security

		WinWait( "Notice", "You must be an Administrator", 60 )
		WinActivate( "Notice", "You must be" )
		ControlClick( "Notice", "You must be", 1 )

		WinWait( "Warning", "For proper installation", 60 )
		WinActivate( "Warning", "For proper" )
		ControlClick( "Warning", "For proper", 2 )
	EndIf

	Return $instState

EndFunc ; <== instSSO

#EndRegion App installs <<

#Region Settings >>

func setNIC()	; GOOD
	local $nicTitle, $nicCount, $nicTitleWired, $speedNameString, $speedStngString, $currentSel, $setWireless, $nicSet, $negFind
	$setWireless = 0

	upStatus( "Setting:	NIC" )

	; Launch devmgmt, focus, and start finding installed NICs
	ShellExecute( "devmgmt.msc" )
	winwaitactive( "Device Manager" )
	ControlFocus( "Device Manager", "", "SysTreeView321" )
	$nicCount = ControlTreeView( "Device Manager", "", "SysTreeView321", "GetItemCount", "#0|Network adapters" )

	dim $nicList[$nicCount]
	for $i = 0 to $nicCount-1	;Fill array with NIC titles
		ControlTreeView( "Device Manager", "", "SysTreeView321", "Select", "#0|Network adapters|#" & $i )
		$nicList[$i] = ControlTreeView( "Device Manager", "", "SysTreeView321", "GetText", "#0|Network adapters|#" & $i )
		upStatus( "NIC " & $i & ": " & $nicList[$i], 0 )
	Next

	; One NIC found
	if $nicCount == 1 Then
		$nicTitle = ControlTreeView( "Device Manager", "", "SysTreeView321", "GetText", "#0|Network adapters|#0" )
	; No NICs found (lolwut)
	Elseif $nicCount == 0 Then
		upStatus( "No network adapters found (you really shouldn't be getting this message)" )
		WinClose( "Device Manager" )
	; Multiple NICs found
	ElseIf $nicCount > 1 Then
		upStatus( $nicCount & " network adapters found" )

		; lazy hack wired finding method
		for $i = 0 to $nicCount
			$currentSel = ControlTreeView( "Device Manager", "", "SysTreeView321", "GetText", "#0|Network adapters|#" & $i)
			if StringInStr( $currentSel, "Gigabit" ) OR StringInStr( $currentSel, "10/100" ) OR StringInStr( $currentSel, "PRO/100" ) Then
				$nicTitle = ControlTreeView( "Device Manager", "", "SysTreeView321", "GetText", "#0|Network adapters|#" & $i)
				upStatus( "Wired NIC: " & $nicTitle )
				ControlTreeView( "Device Manager", "", "SysTreeView321", "Select", "#0|Network adapters|#" & $i)
				ExitLoop
			EndIf
		Next
	EndIf

	if WinExists( "Device Manager" ) Then
		WinActivate( "Device Manager")
		sleep(500)
		send( "{TAB}" )
		send( "{enter}" )
		WinWait( $nicTitle )
		WinActivate( $nicTitle )
		ControlCommand( $nicTitle, "", 12320, "TabRight", "" )
		sleep(750)
		ControlFocus( $nicTitle, "", 1101 )
		Select	; set strings based on primary network adapter / computer model
		Case StringInStr( $nicTitle, "Intel(R)" ); OR $nicTitle == "Intel(R) 82566DM-2 Gigabit Network Connection" ; dell e6500 and 755
			$speedNameString = 'Link Speed & Duplex'
			$speedStngString = 'Auto'
			ProgressSet( 94, "Intel adapter", "Setting NIC to auto" )
		case StringInStr( $nicTitle, "Broadcom" ) OR StringInStr( $nicTitle, "Marvell" ); 440x 10/100 Integrated Controller" OR $nicTitle == "Broadcom NetXtreme 57xx Gigabit Controller"	OR $nicTitle == "Broadcom NetXtreme Gigabit Ethernet" ; dell d510 / d530 / GX280 / 745
			$speedNameString = 'Speed & Duplex'
			$speedStngString = 'Auto'
			ProgressSet( 94, "Broadcom adapter", "Setting NIC to auto" )
		EndSelect

		ControlCommand( $nicTitle, "", 1101, "SelectString", $speedNameString )
		ControlFocus( $nicTitle, "", 1103)
		sleep(250)
		$nicSet = ControlGetText( $nicTitle, "", 1103 )
		$negFind = ControlCommand( $nicTitle, "", 1103, "FindString", 'Auto-negotiate' )

		if $negFind AND $nicSet = "Auto-negotiate" Then
			upStatus( "NIC set correctly" )
			WinClose( $nicTitle )
			WinWaitClose( $nicTitle )
		ElseIf StringInStr( $nicSet, $speedStngString ) Then
			upStatus( "NIC set correctly" )
			WinClose( $nicTitle )
			WinWaitClose( $nicTitle )
		Else
			upStatus( "Link/duplex set to " & $nicSet & ", changing" )

			$negFind = ControlCommand( $nicTitle, "", 1103, "FindString", 'Auto-negotiate' )
			if $negFind Then
				ControlCommand( $nicTitle, "", 1103, "SetCurrentSelection", $negFind )
			Else
				ControlCommand( $nicTitle, "", 1103, "SelectString", $speedStngString )
			EndIf

			upStatus( "Link/duplex changed to " & ControlGetText( $nicTitle, "", 1103 ) )
			sleep(1000)
			ControlClick( $nicTitle, "", 1 )
			WinWaitClose( $nicTitle )
			upStatus( "Waiting for DHCP", 0)
			sleep(3000)

			if $nicCount == 1 Then
				do
					sleep(1000)
					_GUICtrlEdit_AppendText( $editStatus, "." )
				until @IPAddress1 <> "0.0.0.0" AND @IPAddress1 <> "127.0.0.1"
				_GUICtrlEdit_AppendText( $editStatus, @CRLF )
				upStatus( "IP Address:	" & @IPAddress1 )
				sleep(5000)

				if WinExists( "System Settings Change", "Your hardware" ) Then
					ControlClick( "System Settings Change", "Your", 7 )
				EndIf

			EndIf


		EndIf
		WinClose( "Device Manager" )

	EndIf

	return $nicSet

EndFunc ; <== setNIC

func setAL($genID)	; GOOD
	dim $winTitle
	$winTitle = "Random Password Generator for Autologon with Password Encryption"

	upStatus( "Setting:		autologon" )
	upStatus( "ID:			" & $genID )

	ShellExecute( "" )  ; path removed for security
	WinWaitActive( $winTitle, "", 60 )

	if NOT WinExists( $winTitle ) Then Return 2

	sleep(500)
	send( "{TAB} {SPACE}" )
	WinWaitActive( "Add Generic ID to AutoLogon", "Please add", 30 )
	ControlSetText( "Add Generic ID", "Please add", 1000, $genID )
	sleep(500)
	ControlClick( "Add Generic ID", "Please add", 1 )
	WinWaitActive( "AutoLogon", "Autologon successfully configured.", 30 )
	sleep(500)
	ControlClick( "AutoLogon", "Autologon successfully", 2 )
	WinWait( "", "Finished setting up AutoLogon", 30 )
	WinActivate( "", "Finished setting up" )
	sleep(250)
	ControlClick( "", "Finished setting up AutoLogon", 2 )
	sleep(500)
	WinActivate( $winTitle )
	send( "{TAB 2} {SPACE}" )

	upStatus( "Autologon set successfully" )
EndFunc ; <== setAL

func getWireless($setWireless)	; PROBABLY GOOD
	Local $SSID, $Signal, $Noise, $Channel, $APMAC, $channelIndex, $wifiInfo, $winTitle

	upStatus( "Found:	Wireless Connection" )

	Select
	; Intel and Fujitsu/etc. Gets wifi info from MSNdis_80211 WMI classes
	Case $setWireless = (1 OR 4)

		#cs
			$winTitle = "Intel"
			if FileExists( @ProgramFilesDir & "\Intel\Wireless\Bin\iFrmewrk.exe" ) Then
				ShellExecute( @ProgramFilesDir & "\Intel\Wireless\Bin\iFrmewrk.exe" )
			ElseIf FileExists( @ProgramFilesDir & "\Common Files\Intel\WirelessCommon\iFrmewrk.exe" ) Then
				ShellExecute( @ProgramFilesDir & "\Common Files\Intel\WirelessCommon\iFrmewrk.exe" )
			Else
				upStatus( "Intel utility not found (you shouldn't be getting this message" )
			EndIf
			WinWaitActive( $winTitle, "", 30 )
			if WinActive( $winTitle ) Then
				$SSID = ControlGetText( $winTitle, "", 1027 )
				send( "!v" )
				sleep(250)
				send( "s" )
				WinWaitActive( "Advanced Statistics" )
				$Signal = ControlGetText( "Advanced", "", 1119 )
				$APMAC = ControlGetText( "Advanced", "", 1104 )
				ControlClick( "Advanced", "", 1026 )
				WinWaitActive( $winTitle )
				ControlClick( $winTitle, "", 1000 )
				WinWaitActive( "Connection Details" )
				$channelIndex = ControlListView( "Connection Details", "", 1005, "FindItem", "Channel Number" )
				$Channel = ControlListView( "Connection Details", "", 1005, "GetText", $channelIndex, 1 )
				ControlClick( "Connection", "", 1 )
				WinClose( $winTitle )
			Else
				upStatus( "Could not find wireless utility window", 0 )
			EndIf
		#ce

		$wifiInfo = wirelessInfo()

		$SSID = $wifiInfo[0]
		$Signal = $wifiInfo[1]
		$APMAC = $wifiInfo[4]
		$Channel = $wifiInfo[3]

	Case $setWireless == 2
		$winTitle = "Proxim Client Utility - Current Profile: THR"
		ShellExecute( @ProgramFilesDir & "\ORiNOCO\WirelessClient\Utility\orinoco.exe" )
		WinWaitActive( $winTitle )
		ControlClick( $winTitle, "", 1144 )
		WinWaitActive( "Advanced Status" )
		ProgressSet( 7, "Gathering wireless info", "Wireless client found" )
		$SSID = ControlGetText( "Advanced", "", 1015 )
		$Signal = ControlGetText( "Advanced", "", 1009 )
		$Noise = ControlGetText( "Advanced", "", 1011 )
		$Channel = ControlGetText( "Advanced", "", 1039 )
		$APMAC = ControlGetText( "Advanced", "", 1025 )
		ControlClick( "Advanced", "", 1 )
		WinClose( $winTitle )
	Case $setWireless == 3
		$winTitle = "Dell Wireless WLAN Card Utility"
		ShellExecute( "control.exe", @SystemDir & "\bcmwlcpl.cpl" )
		WinWaitActive( $winTitle )
		while ControlCommand( $winTitle, "", "SysTabControl321", "CurrentTab", "") <> 2
			sleep(100)
			ControlCommand( $winTitle, "", "SysTabControl321", "TabRight", "" )
		WEnd
		sleep(500)
		; ============= select different dell utility ersions
		If StringLeft (FileGetVersion( @systemdir & "\bcmwlcpl.cpl" ), 1 ) > 3 Then
			$wifiInfo = wirelessInfo()

			$SSID = $wifiInfo[0]
			$Signal = $wifiInfo[1]
			$APMAC = $wifiInfo[4]
			$Channel = $wifiInfo[3]
			upStatus( "Noise level must be recorded manually.", 0 )
			sleep(5000)
			ControlClick( $winTitle, "", 1 )
		Else
			$SSID = ControlGetText( $winTitle, "", 1000 )
			$Signal = ControlGetText( $winTitle, "", 1097 )
			$Noise = ControlGetText( $winTitle, "", 1023 )
			$Channel = ControlGetText( $winTitle, "", 1033 )
			$APMAC = ControlGetText( $winTitle, "", 1077 )
		EndIf
		; ================
	EndSelect

	if NOT $Noise Then $Noise = "N/A"

	upStatus( "SSID:	" & $SSID )
	upStatus( "Signal:	" & $Signal )
	upStatus( "Noise:	" & $Noise )
	upStatus( "Channel:	" & $Channel )
	upStatus( "AP MAC:	" & StringReplace( StringReplace( $APMAC, ":", "" ), "-", "" ) )
	if $winTitle Then WinClose( $winTitle, "" )

EndFunc ; <== getWireless

func checkBios($model, $biosCurrent)	; PROBABLY GOOD
	; ===========================================================
	;
	; BIOS auto-check section
	;
	;	latest versions for each machine on ftwgen01:
	;		745		2.6.2
	;		755		A12
	;		D620	A09
	;		GX620	A11
	;		GX280	A08
	;		GX270	A07
	;		SX280	A05
	;
	; ===========================================================

	Dim $q = MsgBox(36, " Healthcheck", "Check and/or flash BIOS?" )

	if $q = 7 Then Return $q

	Select
	Case $model = "OptiPlex 755"
		if $biosCurrent == "A12" Then
			Return
		Else
			ShellExecute( "755\O755-A12.exe" )  ; path removed for security
		EndIf
	Case $model = "OptiPlex 745"
		if $biosCurrent == "2.6.2" Then
			Return
		Else
			ShellExecute( "745\o745-020602.exe" )  ; path removed for security
		EndIf
	;Case $model = "d620"
	;	ShellExecute( "D620\D620_A09.exe" )
	Case $model = "OptiPlex GX620"
		if $biosCurrent == "A11" Then
			Return
		Else
			ShellExecute( "GX620\A11GX620.exe" ) ; path removed for security
		EndIf
	Case $model = "OptiPlex GX280"
		if $biosCurrent == "A08" Then
			Return
		Else
			ShellExecute( "GX280\GX280A08.exe" ) ; path removed for security
		EndIf
	Case $model = "OptiPlex GX270"
		if $biosCurrent == "A07" Then
			Return
		Else
			ShellExecute( "GX270\GX270A07.exe" ) ; path removed for security
		EndIf
	Case $model = "OptiPlex SX280"
		if $biosCurrent == "A05" Then
			Return
		Else
			ShellExecute( "SX280\SX280A05.exe" ) ; path removed for security
		EndIf
	EndSelect

	WinWaitActive( "Dell BIOS Flash", "", 15 )
	sleep(1000)

	Dim $biosNew = StringTrimLeft( controlgettext( "Dell BIOS Flash", "", 1009 ), 11 )

	if ControlGetText( "Dell BIOS Flash", "", 1014 ) == "BIOS upgrade supported." AND $biosCurrent <> $biosNew Then
		ControlClick( "Dell BIOS Flash", "", 1001 )
		WinWaitActive( "Dell System", "Confirm - Replace" )

		upStatus( "Flashing BIOS to version:	" & $biosNew & " in 5s" )
		Sleep(1000)
		upStatus( "4...", 0 )
		Sleep(1000)
		upStatus( "3...", 0 )
		Sleep(1000)
		upStatus( "2...", 0 )
		Sleep(1000)
		upStatus( "1.", 0 )
		Sleep(1000)
		ControlClick( "Dell System", "Confirm - Replace", 1 )
	Else
		upStatus( "BIOS up-to-date (" & $biosNew & ")" )
		Sleep(500)
		ControlClick( "Dell BIOS Flash", "", 1002 )
	EndIf

EndFunc ; <== checkBios

#EndRegion Settings <<

#Region Misc (upStatus, timeFormat) >>

func upStatus($statusLine, $log = 1)
	local $winLength = 44	;number of fixed-width characters to write before wrapping

	; Old text wrapping method; no longer needed with the updated GUIEdit include
	#cs
	if StringLen( $statusLine ) > $winLength Then
		_GUICtrlEdit_AppendText( $editStatus, @HOUR & ":" & @MIN & ":" & @SEC & "> " & StringLeft( $statusLine, $winLength ) & @CRLF )
		For $i = 1 to Floor( stringlen( $statusLine ) / $winLength )
			_GUICtrlEdit_AppendText( $editStatus, "         > " & StringMid( $statusLine, ($i * $winLength)+1, $winLength ) & @CRLF )
		Next
	Else

		_GUICtrlEdit_AppendText( $editStatus, @HOUR & ":" & @MIN & ":" & @SEC & "> " & $statusLine & @CRLF)
	EndIf
	#ce

	_GUICtrlEdit_AppendText( $editStatus, @HOUR & ":" & @MIN & ":" & @SEC & "> " & $statusLine & @CRLF)

	; Write to logfile simultaneously
	if $log then _FileWriteLog( $pathLog, $statusLine )

EndFunc ; <== upStatus

func timeFormat($ms)
	dim $sec, $min, $hr
	dim $s = round($ms/1000, 0 )

	$sec = mod($s, 60)
	if $sec < 10 then $sec = "0" & $sec
	$min = Floor(mod($s/60, 60))
	if $min < 10 then $min = "0" & $min
	$hr = Floor($s/3600)
	if $hr < 10 then $hr = "0" & $hr

	Return $hr & "h " & $min & "m " & $sec & "s"

EndFunc ; <== timeFormat

#EndRegion Misc <<
